<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="__ROOT__assets/js/jquery-1.9.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
    // 证书是会检查域名的，请使用域名连接
    /*ws = new WebSocket("wss://cp.xiaohaotech.com:9899");
     ws.onopen = function() {
     alert("连接成功");
     ws.send('tom');
     alert("给服务端发送一个字符串：tom");
     };
     ws.onmessage = function(e) {
     alert("收到服务端的消息：" + e.data);
     };*/
    var ws,uid=1;
    function connect(){
        ws = new WebSocket("ws://127.0.0.1:8282");
        ws.onopen=open;
        ws.onmessage=umessage;
        ws.onclose=close;
        ws.onerror = function(msg) {
            console.log("出现错误",msg);
            //connect();
        };
    }
    function open()
    {
        //alert('链接成功')
        //var login_data="10002:01";
        //var login_data='{"uid":"'+uid+'","content":"login","type":"login"}';
        //ws.send(login_data);
    }
    function umessage(msg){
        console.log(msg);

        //$('#lr').append('<tr><td>'+msg.uid+'</td><td>'+msg.content+'</td><td>'+msg.type+'</td>');
    }
    // 连接建立时发送登录信息

    function close(msg){
        console.log("连接关闭，定时重连",msg);
        //connect();
    }
    function wo(){
        //var data='{"uid":"34","content":"lfogin","type":"loginf"}';
        var data='fsdfsd';
        ws.send(data);
    }
    function SendData() {
        try{
            var content = document.getElementById("content").value;
            if(content){
                ws.send(content);
            }

        }catch(ex){
            alert(ex.message);
        }
    }

    function seestate(){
        alert(ws.readyState);
    }
    function opendoor(){

    }
    function lend_book(){
        var login_data="10001:04,1,1,1000003";
        ws.send(login_data);
    }
    function return_book(){
        var login_data="10001:05,1,1,1000003";
        ws.send(login_data);
    }
    function closedoor(){
        console.log('关锁成功')
        //alert('关锁成功');
        ws.send("10001:06,1");
    }
    $(function(){
        connect();
    })
    l
</script>
<div>
    <div>用户列表</div>
    <ul>
        <li>11</li>
    </ul>
</div>
<div onclick="opendoor()">
    开锁
</div>
<textarea name="content" rows="10" cols="50">

</textarea>
<button type="button">发送</button>
</div>
</body>
</html>